﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-12-13 15:47:19
// 负责人：Sushee
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
namespace OF.Component.DAL
{
	
	/// <summary>
	/// 数据访问层
	/// </summary>	
	internal partial class AuthoritySystem
	{		
    
        /// <summary>
    	/// 根据断言条件获取单个
    	/// </summary>
        public AuthoritySystemInfo QuerySingle(Expression<Func<AuthoritySystemInfo, bool>> predicate)
	    {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }
        /// <summary>
    	/// 根据断言条件获获取列表
    	/// </summary>
	    public IList<AuthoritySystemInfo> QueryList(Expression<Func<AuthoritySystemInfo, bool>> predicate)
	    {
	        return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
	    }

        /// <summary>
        /// 根据角色获取所对应系统信息
        /// </summary>
        /// <param name="roleIds"></param>
        /// <returns></returns>
        public IList<AuthoritySystemInfo> GetSystemInfoByRoleIds(List<int> roleIds)
        {
            IList<AuthoritySystemInfo> list = new List<AuthoritySystemInfo>();
            if (roleIds.Count == 0)
            {
                return list;
            }
            string intRoleIds = string.Join(",", roleIds.ToArray());

            List<string> roleNameList = null;
            string strSql = @"select * from AuthoritySystem where systemid in(
							  select systemid from AuthorityRoleMenuRela where IsActive=1 and roleid in(" + intRoleIds + ") group by systemid) order by OrderNum ";
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(strSql);
            //设置参数
            using (IDataReader dr = db.ExecuteReader(dbc))
            {
                while (dr.Read())
                {
                    list.Add(SQLServerProvider.Create<AuthoritySystemInfo>(dr));
                }
            }
            return list;
        }
    }
	
}